package com.company.emallbackend.controller;

import com.company.emallbackend.common.Result;
import com.company.emallbackend.entity.Order;
import com.company.emallbackend.entity.dto.OrderDTO;
import com.company.emallbackend.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* <p>
*  前端控制器
* </p>
*
* @author hanlijian
* @since 2023-01-12
*/
@RestController
@RequestMapping("/order")
@Api(tags = "订单管理")
public class OrderController {

    @Resource
    private IOrderService orderService;

    /**
     * 下单
     * @param orderDTO
     * @return
     */
    @PostMapping("addOrder")
    @ApiOperation("下单")
    public Result addOrder(@RequestBody OrderDTO orderDTO, HttpServletResponse response){
        orderService.addOrder(orderDTO,response);
        return Result.success();
    }

    /**
     * 查询我的订单列表
     * @return
     */
    @GetMapping("getMyOrderList")
    @ApiOperation("查询我的订单列表")
    public Result getMyOrderList(){
        List<Order> orderList=orderService.getMyOrderList();
        return Result.success(orderList);
    }

    /**
     * 异步回调
     * @param request
     * @return
     */
    @PostMapping("notify")
    public Result notify(HttpServletRequest request){
        orderService.payNotify(request);
        return Result.success();
    }

    /**
     * 根据订单号查询订单
     * @param orderNo
     * @return
     */
    @GetMapping("queryTrade/{orderNo}")
    @ApiOperation("根据订单号查询订单")
    public String queryOrder(@PathVariable String orderNo){
        String body=orderService.queryOrder(orderNo);
        return body;
    }

    /**
     * 查询已支付商品
     * @return
     */
    @GetMapping("queryPayOrder")
    @ApiOperation("查询已支付订单列表")
    public Result queryPayOrder(){
        List<Order> orderList=orderService.queryPayOrder();
        return Result.success(orderList);
    }

    /**
     * 根据订单id发货商品
     * @param orderId
     * @return
     */
    @PutMapping("deliverGoods/{orderId}")
    @ApiOperation("根据订单id发货商品")
    public Result deliverGoods(@PathVariable("orderId")Integer orderId){
        orderService.deliverGoods(orderId);
        return Result.success();
    }
    
    /*@GetMapping("ok")
    public String ok(){
        return "success";
    }*/
    
    
    
}
